package com.java.tutorials.mongodb;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import org.bson.Document;

/**
 * Created by xuzhike on 2016/1/3.
 */
public class MongoDBDemo {
    public static void main(String[] args) {
//        Mongo mongo = new Mongo("localhost", 27017);
        MongoClient mongoClient = new MongoClient("localhost", 27017);
        String collectionName = "person_basic";
//        mongoClient.getDatabase("mongodb_test").createCollection(collectionName);
        MongoCollection<Document> collection = mongoClient.getDatabase("mongodb_test").getCollection(collectionName);
        // 插入多条
        for (int i = 10; i <= 40; i++) {
            Document doc = new Document();
            doc.put("name", "zhoulf");
            doc.put("school", "NEFU" + i);
            Document interests = new Document();
            interests.put("game", "game" + i);
            interests.put("ball", "ball" + i);
            doc.put("interests", interests);
            collection.insertOne(doc);
        }
//        MongoDatabase database = mongoClient.getDatabase("mongodb_test");
    }
}
